package grg.learn.compose.ui.ui.main

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import grg.learn.compose.R
import grg.learn.compose.ui.theme.Theme

/**
 * create by iso88591 at 2021/8/22 😟
 * toolbar
 */
@Composable
fun MainToolBar(
    title: String,
    theme: Theme,
    modifier: Modifier = Modifier,
    left: @Composable () -> Unit,
    right: @Composable () -> Unit,
) {

    Box(
        modifier
            .fillMaxWidth(),
        contentAlignment = Alignment.Center
    ) {
        BasicText(
            text = title,
            style = TextStyle(
                color = theme.primaryTextColor,
                fontSize = 16.sp,// theme.primaryTextSize,
                textAlign = TextAlign.Center
            ),
        )

        Box(
            Modifier
                .fillMaxWidth()
                .fillMaxHeight(1f),
            contentAlignment = Alignment.TopStart
        ) {
            left()
        }

        Box(
            Modifier
                .fillMaxWidth()
                .fillMaxHeight(1f),
            contentAlignment = Alignment.BottomEnd
        ) {
            right()
        }
    }

}

@Composable
fun MainToolBarMoreAction(
    modifier: Modifier = Modifier
) {
    Image(
        painter = painterResource(id = R.drawable.ic_add),
        contentDescription = "更多操作",
        modifier = modifier.padding(15.dp)
    )
}